<template>
  <div style="text-align:center;">
    <div class="page">
      <div @click="changeCurrentPage('back')">
        <i class="iconfont iconicon_narrow_left_s"></i>
      </div>
      <div
        @click="changeCurrentPage(item)"
        v-for="(item,index) in pageArr"
        :key="index"
        class="pageItem"
        :class="{item:item == currentPage}"
      >{{item}}</div>
      <div @click="changeCurrentPage('font')">
        <i class="iconfont iconarrow-right"></i>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, defineProps, defineEmits } from 'vue'
const props = defineProps({
  pageNum: {
    type: Number,
    default: 0
  },
  currentPage: {
    type: Number,
    default: 1
  }
})
let emits = defineEmits(['changeCurrentPage'])
const changeCurrentPage = item => {
  let items
  switch (item) {
    case 'back':
      props.currentPage > 0 && (items = props.currentPage - 1)
      break
    case 'font':
      props.currentPage < props.pageNum && (items = props.currentPage + 1)
      break
    default:
      items = item
  }
  items && emits('changeCurrentPage', items)
}
const pageArr = computed(() => {
  let pageArrTem: Array<number> = []
  let i = 0
  while (i < props.pageNum) {
    i++
    pageArrTem.push(i)
  }
  return pageArrTem
})
</script>

<style lang="less" scoped>
.page {
  margin: 30px auto 80px;
  text-align: center;
  color: #fff;
  display: inline-flex;
  div {
    font-size: 12px;
    border: 1px solid #3b3b3b;
    width: 24px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    border-radius: 5px;
    margin: 0 2px;
    font-weight: bolder;
    color: #878787;
    .iconfont {
      font-size: 12px;
    }
    &:hover {
      cursor: pointer;
      background-color: #2d2d2d;
      color: #b5b5b5;
    }
  }
}
.item {
  color: #fff !important;
  background-color: #c3473a !important;
}
</style>